<template>
	<view class="login-container">
		<view class="login-container-title">
			<view class="login-container-title-top">
				<text>登录</text>
			</view>
			<text>欢迎</text>
		</view>
		<view class="login-container-content">
			<view class="login-container-content-row">
				<image src="@/static/image/login/username.png"></image>
				<input type="text" v-model="userName" placeholder="用户名" />
			</view>
			<view class="login-container-content-row">
				<image src="@/static/image/login/password.png"></image>
				<input :password="!showPassword" v-model="password" placeholder="密码"/>
				<view class="login-container-content-row-bt" @click="showPassword=!showPassword">
					<u-icon :name="showPassword?'eye':'eye-off'" color="#999999" size="38"></u-icon>
				</view>
			</view>
		</view>
		<button type="default" class="login-container-button" @click="login" :disabled="loading">{{loading ? "登录中...":" 登录 "}}</button>
	</view>
</template>

<script>
import { login } from '@/api/index.js'
// import VConsole from 'vconsole'
	export default {
		data: () => {
			return {
				loading: false,
				showPassword: false,//是否显示密码
				userName: 'admin',
				password: '123456',
				code: '',
                auth:'',
                authSer:'',
			}
		},
        async onShow() {
		    let _ = this
			// const vConsole = new VConsole()
		},
		methods: {
			showPwd(){
				this.show = !this.show
			},
			//验证
			validation(){
				let _ = this
				if (_.$V.isEmpty(_.userName)) {
				  this.$T.showToast('请先输入用户名')
				  return false
				}
				if (_.$V.isEmpty(_.password)) {
				  this.$T.showToast('请先输入密码')
				  return false
				}
				return true
			},
			//登录
			async login() {
				let _ = this
				if(!_.validation()) return
				_.loading = true
				let data = {
					simCard: _.userName,
					password: _.password,
				}
                _.$u.vuex('loginInfo', {u: _.userName, p: _.password})
				try {
				    // const { data: res } = await login(data)
					let res = {
					    data:{
					        code:200,
							token:'tk007'
						}
					}
					if(res.data.code==200) {
                        _.$u.vuex('token', res.data.token);
                        _.$u.vuex('userInfo', {username:'wxb',simCard:'13656191111'});
                        uni.setStorageSync('Authorization', res.data.token)
						uni.switchTab({ url: '/pages/home/index' })
						_.loading = false
					} else {
						_.$T.showToast(res.msg)
						_.loading = false
					}
				} catch (e) {
						_.loading = false
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
@import 'index.scss';
</style>
